<?php

namespace app\widgets;

use yii;

class AppMenuWidget extends yii\widgets\Menu {

    public $encodeLabels = FALSE;
    public $activeCssClass = 'active';
    public $options = ['class' => 'nav nav-menu'];
    public $itemOptions = ['class' => 'nav-item'];
    public $linkTemplate = '<a class="nav-link" href="{url}">{label}</a>';
    public $submenuTemplate = "\n<ul class=\"sub-menu\">\n{items}\n</ul>\n";


    public function init() {
        parent::init();
        $this->route = str_replace('/index', '/', $this->route);

        $this->items = [
            ['label' => '终端用户管理 <span class="caret"></span>', 'url' => 'javascript:void(0);', 'items' => [
                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>用户管理', 'url' => 'index.php?r=user/index'],
                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>用户组管理', 'url' => 'index.php?r=group/index'],
                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>硬件信息', 'url' => 'index.php?r=hardware/index'],

//                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>文件管理', 'url' => 'index.php?r=file/index']
            ]],
//            ['label' => '设备管理 <span class="caret"></span>', 'url' => 'javascript:void(0);', 'items' => [
//                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>网卡管理', 'url' => 'index.php?r=user/index'],
//                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>活动网卡管理', 'url' => 'index.php?r=user-group/index']
//            ]],
//            ['label' => '资源管理 <span class="caret"></span>', 'url' => 'javascript:void(0);', 'items' => [
//                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>资源包管理', 'url' => 'index.php?r=user/index'],
//                ['label' => '<i class="glyphicon glyphicon-menu-right"></i>动态库管理', 'url' => 'index.php?r=user-group/index']
//            ]],
            ['label' => '退出登录 <span class="caret"></span>', 'url' => 'index.php?r=site/logout'],
        ];
    }


//    protected function isItemActive($item) {
//        if (!isset($item['url'])) {
//            return FALSE;
//        }
//
//        $route = ltrim($item['url'][0], '/');
//        if (in_array($route, ['', '/']) && trim($this->route, '/') === Yii::$app->controller->module->defaultRoute) {
//            return TRUE;
//        }
//        $slug = strtolower(Yii::$app->request->get('slug'));
//        if ($slug) {
//            $this->route = "{$slug}/";
//        }
//
//        return parent::isItemActive($item);
//    }
}